package com.ruoyi.web.controller.wlsggk;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.waterdrop.wlsggk.pojo.TransferInventory;
import com.waterdrop.wlsggk.service.ITransferInventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 中转仓库Controller
 *
 * @author Naruto
 * @date 2023-10-23
 */
@RestController
@RequestMapping("/wlsggk/transfer")
public class TransferInventoryController extends BaseController {
    @Autowired
    private ITransferInventoryService transferInventoryService;

    /**
     * 查询中转仓库列表
     */
    @PreAuthorize("@ss.hasPermi('wlsggk:transfer:list')")
    @GetMapping("/list")
    public TableDataInfo list(TransferInventory transferInventory) {
        startPage();
        List<TransferInventory> list = transferInventoryService.selectTransferInventoryList(transferInventory);
        return getDataTable(list);
    }

    /**
     * 导出中转仓库列表
     */
    @PreAuthorize("@ss.hasPermi('wlsggk:transfer:export')")
    @Log(title = "中转仓库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TransferInventory transferInventory) {
        List<TransferInventory> list = transferInventoryService.selectTransferInventoryList(transferInventory);
        ExcelUtil<TransferInventory> util = new ExcelUtil<TransferInventory>(TransferInventory.class);
        util.exportExcel(response, list, "中转仓库数据");
    }

    /**
     * 获取中转仓库详细信息
     */
    @PreAuthorize("@ss.hasPermi('wlsggk:transfer:query')")
    @GetMapping(value = "/{transferId}")
    public AjaxResult getInfo(@PathVariable("transferId") Long transferId) {
        return success(transferInventoryService.selectTransferInventoryByTransferId(transferId));
    }

    /**
     * 新增中转仓库
     */
    @PreAuthorize("@ss.hasPermi('wlsggk:transfer:add')")
    @Log(title = "中转仓库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TransferInventory transferInventory) {
        return toAjax(transferInventoryService.insertTransferInventory(transferInventory));
    }

    /**
     * 修改中转仓库
     */
    @PreAuthorize("@ss.hasPermi('wlsggk:transfer:edit')")
    @Log(title = "中转仓库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TransferInventory transferInventory) {
        return toAjax(transferInventoryService.updateTransferInventory(transferInventory));
    }

    /**
     * 删除中转仓库
     */
    @PreAuthorize("@ss.hasPermi('wlsggk:transfer:remove')")
    @Log(title = "中转仓库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{transferIds}")
    public AjaxResult remove(@PathVariable Long[] transferIds) {
        return toAjax(transferInventoryService.deleteTransferInventoryByTransferIds(transferIds));
    }
}
